package com.study.cloud.controller;

import com.study.cloud.MemberDTO;
import com.study.cloud.MemberServiceApi;
import com.study.cloud.dto.OrderDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {


    Logger logger = LoggerFactory.getLogger(OrderController.class);
    @Autowired
    MemberServiceApi memberServiceApi;

    @GetMapping("/info")
    public OrderDTO getInfo(Integer id){
        MemberDTO memberInfo = memberServiceApi.getMemberInfo(id);
        logger.info("=="+memberInfo.toString());

        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setOrderId("11");
        orderDTO.setOrderInfo(memberInfo.toString());

        TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
            @Override
            public void afterCommit() {

            }
        });

        return orderDTO;
    }
}
